home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr05
/
xnot12a.zip
/
W3EXT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-20
|
8KB
|
288 lines
#ifdef MSW /* whole file */
/* Extended ms window functions - ie drag & drop, clipboard, print.
*/
#include "jam.h"
#include "def.h"
#include "time.h"
#include "malloc.h"
#include "commdlg.h"
#include "shellapi.h"
static char *noclipbtext = "No text on clipboard.";
static char *noopencb = "Can't open clipboard.";
static char *nosetcbtext = "Error setting text to clipboard.";
void HandleDroppedFiles(HANDLE hdrop)
{
char fname[NFILEN+1];
register UINT numfiles, len, i;
POINT pt;
int row, col;
BOOL insert;
numfiles = (int)DragQueryFile(hdrop, (UINT)-1, fname, NFILEN+1);
if (numfiles > 0)
{
DragQueryPoint(hdrop, &pt);
GetRowCol(&row, &col, pt.x, pt.y);
dottomouse(row, col, FALSE);
if (minmodeline())
insert = FALSE; /* find-file-other-window */
else
{
insert = TRUE; /* insert at dot */
dottomouse(row, col, TRUE); /* set doto to mouse pos */
}
for (i = 0; i < numfiles; i++)
{
len = DragQueryFile(hdrop, (UINT)i, fname, NFILEN+1);
fname[len] = '\0';
/* Note that both functions execute NOW, placing only
* parameters (if anything) into the input queue. This
* is because this function is occurring as a result of
* another task being active and no cursor could be up
* (displayed) when this command executes. Otherwise, it
* would have to be deferred via complete input-stream
* actions. Note also that this allows many files to be
* read in without overflowing
*/
if (insert)
{
insertfile(adjustname(fname), (char *)0);
}
else
{
AddString(fname);
AddKchar(CCHR('J'));
poptofilequiet(0, 1);
}
}
AsyncUpdate();
}
}
void HandleCutCopy(cut)
BOOL cut;
{
HANDLE handle;
char *kp, *buffer;
RSIZE ksize, nlines;
register RSIZE i, j;
/* nasty to do this here!
*/
if (IsCaretCreated())
SetCaretVis(FALSE);
/* either way, data is in our killbuffer
*/
kdelete(); /* clear the buffer */
clearUndo(curbp);
if (cut)
{
cacheKill();
if (!killregion(0, 1))
{
WindowMessage("Can't delete region; clipboard not updated.", FALSE);
clearUndo(curbp);
return;
}
}
else
if (!copyregion(0, 1))
{
WindowMessage("Can't copy region; clipboard not updated.", FALSE);
return;
}
/* see if got clipboard
*/
if (!OpenClipboard(g_hWnd))
{
WindowMessage(noopencb, FALSE);
return;
}
/* tedious process of figuring out how many
* lines this buffer has in it
*/
kp = killbufstart();
ksize = return_kused();
nlines = 0;
for (i = 0; i < ksize; i++)
if (kp[i] == '\n')
nlines++;
/* allocate memory for clipboard
*/
if (!(handle = GlobalAlloc(GMEM_MOVEABLE, ksize + (2 * nlines) + 1)) ||
!(buffer = (char *)GlobalLock(handle)))
{
WindowMessage("Can't get memory to copy data.", FALSE);
if (handle)
GlobalFree(handle);
CloseClipboard();
return;
}
/* copy stuff to global mem, adding newline info..
*/
for (j = i = 0; i < ksize; )
{
if (kp[i] == '\n')
buffer[j++] = '\r';
buffer[j++] = kp[i++];
buffer[j] = '\0'; /* always terminate with prejudice */
}
GlobalUnlock(handle);
if (!SetClipboardData(CF_TEXT, handle))
WindowMessage(nosetcbtext, FALSE);
CloseClipboard();
noop();
}
void HandlePaste()
{
HANDLE hClipb;
char *clipdata, *buffer;
int len;
if (!IsClipboardFormatAvailable(CF_TEXT))
{
WindowMessage(noclipbtext, FALSE);
return;
}
if (!OpenClipboard(g_hWnd))
{
WindowMessage(noopencb, FALSE);
return;
}
if (hClipb = GetClipboardData(CF_TEXT))
{
register char *s, *p;
RSIZE nbytes = 0;
clipdata = GlobalLock(hClipb);
buffer = malloc((len = strlen(clipdata)) + 1);
strcpy(buffer, clipdata);
buffer[len] = '\0';
GlobalUnlock(hClipb);
clearUndo(curbp);
for (s = p = buffer; *p; p++)
if (*p == '\r')
{
p += 2; /* carriage control */
continue;
}
else
nbytes++;
cacheInsert(nbytes);
for (s = p = buffer; ; p++)
if (*p == '\0')
{
lineinsert(s, FALSE); /* add line */
break; /* end of buffer */
}
else if (*p == '\r')
{
*p = '\0';
p += 2; /* past ^M and ^J */
lineinsert(s, TRUE); /* add line */
s = p; /* start new line */
}
free(buffer);
noop();
/*ExtendedFunction(function_name(refresh)); update */
}
CloseClipboard();
}
/* quite simpleminded print function
*/
#ifdef DOPRINT
void HandlePrint()
{
PRINTDLG printdlg;
WindowSleepCursor();
memset(&printdlg, 0, sizeof(PRINTDLG));
printdlg.lStructSize = sizeof(PRINTDLG);
printdlg.hwndOwner = g_hWnd;
printdlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
PD_HIDEPRINTTOFILE | PD_USEDEVMODECOPIES;
if (PrintDlg(&printdlg) != 0)
{
DOCINFO info;
TEXTMETRIC textmetric;
int pageht, numlines, lineheight;
/* use default font in hdc...set up lines per page, etc
*/
GetTextMetrics(printdlg.hDC, &textmetric);
lineheight = textmetric.tmExternalLeading + textmetric.tmHeight;
pageht = GetDeviceCaps(printdlg.hDC, VERTRES);
/* start at line 2, stop 2 from bottom, col 2
*/
numlines = (pageht/lineheight) -4;
info.cbSize = sizeof(DOCINFO);
info.lpszDocName = curbp->b_fname;
info.lpszOutput = NULL;
if (StartDoc(printdlg.hDC, &info) >= 0)
{
register int i, j, k;
register LINE *lp;
char line[NLINE];
char c;
for (lp = lforw(curbp->b_linep); lp != curbp->b_linep; )
{
StartPage(printdlg.hDC);
for (i = 2; i < numlines; i++)
{
/* make an output line; strip control chars, etc
*/
k = 0;
line[k] = '\0';
for (j = 0; (j < llength(lp)) && (k < NLINE); j++)
{
c = lgetc(lp, j);
if (((c < ' ') || (c > '~')) && (c != '\t'))
continue;
line[k++] = c;
line[k] = '\0';
}
/* start at col 2
*/
TextOut(printdlg.hDC, 2 * textmetric.tmMaxCharWidth,
i * lineheight, line, strlen(line));
lp = lforw(lp);
if (lp == curbp->b_linep)
break;
}
EndPage(printdlg.hDC);
}
EndDoc(printdlg.hDC);
}
DeleteDC(printdlg.hDC);
if (printdlg.hDevMode != NULL)
GlobalFree(printdlg.hDevMode);
if (printdlg.hDevNames != NULL)
GlobalFree(printdlg.hDevNames);
}
WindowNormalCursor();
}
#endif /* DOPRINT */
#endif /* MSW */